package com.syh.jn.scm.domain.operation.entity.system;

import cn.redscarf.commons.util.bean.ExtBeanUtils;
import cn.redscarf.commons.util.other.ExtAssert;
import cn.redscarf.commons.util.validator.ValidationUtils;
import com.syh.core.ddd.domain.AbstractSimpleAggregate;
import com.syh.jn.scm.dto.operation.system.dict.DictMto;
import com.syh.jn.scm.dto.operation.system.dict.DictSto;
import com.syh.jn.scm.exception.BusinessException;
import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * Date:2018/7/13
 * Author:Clown
 * 运营平台字典;
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class Dict extends AbstractSimpleAggregate<Long> {

  public Dict() {
  }

  ;

  public Dict(DictSto sto) {
    ExtAssert.notNull(sto, "对象为空");
    ValidationUtils.validate(sto);
    ExtBeanUtils.copyProperties(sto, this, false);
    this.createTimeStamp = System.currentTimeMillis();
    this.status = 1;
  }

  public void modify(DictMto mto) {
    ExtAssert.notNull(mto, "对象为空");
    ValidationUtils.validate(mto);
    ExtBeanUtils.copyProperties(mto, this, false);
    this.lastUpdateTimeStamp = System.currentTimeMillis();
  }

  /**
   * 启用字典
   */
  public void enabled() {
    this.status = 1;
  }

  /**
   * 停用字典
   */
  public void disabled() {
    this.status = -1;
  }

  /**
   * 数据销毁
   */
  public void destroy() {
    if (this.status.equals(Short.valueOf("1"))) {
      throw new BusinessException("字典已启用,删除失败!");
    }
  }

  /**
   * 名称
   */
  private String name;
  /**
   * 值
   */
  private String value;
  /**
   * 状态(启用、停用)
   */
  private Short status;
  /**
   * 编码
   */
  private String code;
  /**
   * 备注
   */
  private String remark;
  /**
   * 分类id
   */
  private Long categoryId;
  /**
   * 分类编码
   */
  private String categoryCode;
  /**
   * 分类名称
   */
  private String categoryName;
}
